import { execSync, spawn, spawnSync } from "child_process";
import { BasePlatform } from "./BasePlatform";
import path from 'path';
import PackUtil from "../utils/PackUtil";
import { ChannelInfo } from "./PlatformConfig";
import { existsSync, readFileSync, writeFileSync } from "fs";
export class WebMobile extends BasePlatform {
    public async afterBuildFinish() {
        let channelInfo: ChannelInfo = this.configData.platforms[this.curPackChannel];
        let remotepath = path.join(this.outputPath, channelInfo.platform);
        //@ts-ignore
        if (existsSync(remotepath) && channelInfo.remoteDir != "" && !global.isPackLocal) {
            console.log('upload cdn res start');
            let cdnrespath = channelInfo.remoteDir;
            PackUtil.mkdirSync(channelInfo.remoteDir);
            PackUtil.pullCDNRes(cdnrespath);
            PackUtil.copyFiles(remotepath, cdnrespath);
            PackUtil.uploadCDNRes(cdnrespath);
            console.log('upload cdn res finish');
        }
        //@ts-ignore
        if (global.isPackLocal) {
            console.log('move files start')
            let local = path.join(this.outputPath, channelInfo.platform + "local");
            // if (existsSync(local)) {
            //     PackUtil.removeFiles(local);
            // }
            PackUtil.mkdirSync(local);
            PackUtil.copyFiles(remotepath, local);
            console.log('move files end')
            if (channelInfo.localPath) {
                channelInfo.serverPath = channelInfo.localPath;
            }else{
                channelInfo.serverPath = "http://192.168.20.58:5500/"
            }
        }
        //上传
        await super.afterBuildFinish();
    }
}